package com.meiya.baseweb.entity;

import java.io.Serializable;

import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;

/**
 * Serializable 接口用于序列号
 * 非ID字段OneToOne关联时关联实体需实现该接口
 * 
 * Cloneable 便于实现深克隆
 * 
 * @author chenc
 *
 */

@MappedSuperclass
public class BasicEntity implements Serializable, Cloneable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private int id;
	
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	@Override
	public Object clone() {
		try {
			return super.clone();
		} catch (CloneNotSupportedException e) {
			return null;
		}
	}

	/**
	 * 默认使用id进行比较。注意不要将不同类型对象进行比较，否则不同类型对象若id相同则会认为是相同对象。
	 */
	@Override
	public boolean equals(Object obj) {
		return this.getClass().equals(obj.getClass())&&this.getId()==((BasicEntity)obj).getId();
	}
	
	

}
